package com.slkj.shilixiaoyuanapp.ui.user.activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.slkj.shilixiaoyuanapp.R;
import com.slkj.shilixiaoyuanapp.base.ActivityInfo;
import com.slkj.shilixiaoyuanapp.base.BaseActivity;
import com.slkj.shilixiaoyuanapp.entity.ToolWorkListEntity;
import com.slkj.shilixiaoyuanapp.entity.VersionHistoryEntity;
import com.slkj.shilixiaoyuanapp.net.HttpHeper;
import com.slkj.shilixiaoyuanapp.net.callback.CommonCallBack;
import com.slkj.shilixiaoyuanapp.ui.teacher.tool.homework.WorkDetailsActivity__JumpCenter;
import com.slkj.shilixiaoyuanapp.ui.teacher.tool.homework.WorkHistoryListActivity;
import com.slkj.shilixiaoyuanapp.view.DividerItemDecoration;
import com.slkj.shilixiaoyuanapp.view.StateLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

@ActivityInfo(layout = R.layout.gong_neng_jie_shao, title = "系统通知")
public class GongNengJieShaoActivity extends BaseActivity {
    @BindView(R.id.recycer)
    RecyclerView recycer;
    @BindView(R.id.statelayout)
    StateLayout statelayout;
    List<VersionHistoryEntity> datas = new ArrayList<>();
    BaseQuickAdapter adapter;


    @Override
    protected void init() {
        recycer.addItemDecoration(new DividerItemDecoration(this, LinearLayoutManager.VERTICAL));
        recycer.setLayoutManager(new LinearLayoutManager(this));
        adapter = new BaseQuickAdapter<VersionHistoryEntity, BaseViewHolder>(R.layout.item_my_vasion, datas) {
            @Override
            protected void convert(BaseViewHolder helper, final VersionHistoryEntity item) {
                helper.setText(R.id.tv_time, item.getIntime())
                        .setText(R.id.tv_title, "十力校园"+item.getVersionNumber()+"主要更新");
                helper.itemView.setOnClickListener(v -> {
                    GengXinXqActivity__JumpCenter.builder(GongNengJieShaoActivity.this).setContent(item.getContent()).create().go();

                });
            }
        };
        recycer.setAdapter(adapter);
        getdata();
        statelayout.setOnReLoadListener(this::getdata);
    }


    protected void getdata() {
        HttpHeper.get().userService()
                .getHistoryVersion(1)
                .compose(getThread())
                .compose(bindToLifecycle())
                .subscribe(new CommonCallBack<List<VersionHistoryEntity>>(statelayout) {
                    @Override
                    public void onCallBackSuccess(List<VersionHistoryEntity> data) {
                        datas.addAll(data);
                        adapter.notifyDataSetChanged();
                    }
                });
    }
}
